<template>
	<view class="container">
		<view class="navigation">
			<uni-icons type="bars" size="30" color="#ffffff"
				@click="$tab.navigateTo('/pages/userInfo/userInfo')"></uni-icons>
			<view class="navigation-center">
				<svg t="1727956152858" class="icon" viewBox="0 0 1024 1024" version="1.1"
					xmlns="http://www.w3.org/2000/svg" p-id="1901" width="28" height="28">
					<path
						d="M1008.794182 514.180666c0 51.085492-41.412179 92.498694-92.497671 92.498694L112.022864 606.679359c-51.083445 0-92.497671-41.413202-92.497671-92.498694l0 0c0-51.083445 41.413202-92.497671 92.497671-92.497671l804.27467 0C967.382003 421.682995 1008.794182 463.096197 1008.794182 514.180666L1008.794182 514.180666z"
						fill="#00A651" p-id="1902"></path>
					<path
						d="M514.159688 19.547195c51.085492 0 92.498694 41.412179 92.498694 92.496647l0 804.273646c0 51.085492-41.413202 92.498694-92.498694 92.498694l0 0c-51.084469 0-92.497671-41.413202-92.497671-92.498694L421.662017 112.043842C421.66304 60.959374 463.076242 19.547195 514.159688 19.547195L514.159688 19.547195z"
						fill="#00A651" p-id="1903"></path>
				</svg>
				<text style="margin-left: 30rpx;font-size: 32rpx;">医邻</text>
			</view>
			<uni-icons type="notification-filled" size="30" color="#ffffff"></uni-icons>
		</view>
		<view class="main-container">
			<view class="search-container">
				<input class="search-input" type="text" placeholder="查询记录.." />
				<button class="search-button">搜索</button>
			</view>
			<view class="sub-container">
				<u-tabs :list="tabList" @click="tabClick" lineWidth="30" lineColor="#f56c6c" :activeStyle="{
            color: '#303133',
            fontWeight: 'bold',
            transform: 'scale(1.05)'
        }" :inactiveStyle="{
            color: '#606266',
            transform: 'scale(1)'
        }" itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;"></u-tabs>
			</view>
			<scroll-view scroll-y="true" class="info-container">
				<view class="info-card" v-for="item in infoList" :key="item.id" style="margin-top: 20rpx;">
					<image class="doctor-avatar" src="@/static/images/doctor-avatar.png" mode="aspectFill"></image>
					<view class="info-section">
						<view class="card-header">
							<text class="title">预约卡片</text>
						</view>
						<view class="card-body">
							<view class="item">
								<text class="label">预约时间:</text>
								<text class="value">{{ item.appointment_time }}</text>
							</view>
							<view class="item">
								<text class="label">姓名:</text>
								<text class="value">{{ item.username }}</text>
							</view>
							<view class="item">
								<text class="label">年龄:</text>
								<text class="value">{{ item.age }}</text>
							</view>
							<view class="item">
								<text class="label">性别:</text>
								<text class="value">{{ item.sex }}</text>
							</view>
							<view class="item">
								<text class="label">问诊类型:</text>
								<text class="value">{{ item.type }}</text>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
			<uni-fab :pattern="pattern" :horizontal="horizontal" :vertical="vertical" :direction="direction"
				@fabClick="fabClick"></uni-fab>
		</view>
	</view>
</template>

<script>
	import { queryPhysicianInquiryRecord } from '../api/system/doctor'
import {
		queryPatientInquiryRecord
	} from '../api/system/patient'
	import {
		toast
	} from '../utils/common'
	export default {
		data() {
			return {
				activeIndex: '0',
				pattern: {
					color: '#7A7E83',
					backgroundColor: '#fff',
					selectedColor: '#007AFF',
					buttonColor: '#7CFC00',
					iconColor: '#fff'
				},
				title: 'uni-fab',
				directionStr: '垂直',
				horizontal: 'left',
				vertical: 'bottom',
				direction: 'horizontal',
				tabList: [],
				infoList: [],
				styles: [{
						value: 'button',
						text: '按钮',
						checked: true
					},
					{
						value: 'text',
						text: '文字'
					}
				],
				colors: ['#007aff', '#4cd964', '#dd524d'],
				current: 0,
				colorIndex: 0,
				activeColor: '#007aff',
				styleType: 'button',
				appointmentTime: '2024-10-08 10:00',
				name: '张三',
				age: '30',
				gender: '男',
				consultationType: '内科'
			}
		},
		onLoad: function() {
			console.log(this.$store.state.user.userInfo.role)
			if (this.$store.state.user.userInfo.role === '患者') {
				this.tabList = [{
						name: '预约信息'
					},
					{
						name: '历史问诊'
					},
				]
			} else if (this.$store.state.user.userInfo.role === '医生') {
				this.tabList = [{
						name: '预约信息'
					},
					{
						name: '待处理问诊'
					},
					{
						name: '历史问诊'
					}
				]
			} else {
				toast('用户角色不存在')
			}
		},
		onShow() {
			this.tabClick({
				index: 0,
				name: '预约信息'
			})
		},
		methods: {
			search() {

			},
			input() {

			},
			async tabClick(e) {
				if (e.name === '预约信息') {
					if(this.$store.state.user.userInfo.role === '患者') {
						const res = await queryPatientInquiryRecord('2')
						this.infoList = res.data[0]
						console.log(this.infoList)
					} else if(this.$store.state.user.userInfo.role === '医生') {
						const res = await queryPhysicianInquiryRecord('4')
						this.infoList = res.data[0]
						console.log(this.infoList)
					}
				} else if(e.name === '待处理问诊') {
					const res = await queryPhysicianInquiryRecord('2')
					this.infoList = res.data[0]
					console.log(this.infoList)
				} else if(e.name === '历史问诊') {
					if(this.$store.state.user.userInfo.role === '患者') {
						const res = await queryPatientInquiryRecord('1')
						this.infoList = res.data[0]
						console.log(this.infoList)
					} else if(this.$store.state.user.userInfo.role === '医生') {
						const res = await queryPhysicianInquiryRecord('1')
						this.infoList = res.data[0]
						console.log(this.infoList)
					}
				} else {
					toast('选项卡出错')
				}
			},
			fabClick() {
				this.$tab.navigateTo('/pages/registration/registration')
			}
		}
	}
</script>

<style lang="scss" scoped>
	// 定义颜色变量
	$green-border-color: #4CAF50;
	$darker-green-border-color: #388E3C;
	$darkest-green-border-color: #1B5E20;
	$input-background-color: #f9f9f9;
	$text-color: #333;
	$button-text-color: white;
	$input-font-size: 16px;
	$shadow-color: rgba(0, 0, 0, 0.1);

	.container {
		height: 100%;
		display: flex;
		flex-direction: column;
		background-color: #ffffff;

		.navigation {
			height: 100rpx;
			padding: 0 30rpx;
			background-color: #84C99A;
			display: flex;
			justify-content: space-between;
			align-items: center;
			color: #ffffff;

			.navigation-center {
				display: flex;
				align-items: center;
			}
		}
	}

	.main-container {
		flex: 1;
		padding: 20rpx;
		display: flex;
		flex-direction: column;
		// 定义颜色变量
		$green-border-color: #4CAF50;
		$darker-green-border-color: #388E3C;
		$darkest-green-border-color: #1B5E20;
		$input-background-color: #f9f9f9;
		$text-color: #333;
		$button-text-color: white;
		$input-font-size: 16px;
		$shadow-color: rgba(0, 0, 0, 0.1);

		.search-container {
			display: flex;
			justify-content: center;
			align-items: center;
			margin: 20rpx; // 边距

			.search-input {
				width: 80%; // 调整宽度以适应屏幕大小
				height: 40px; // 输入框高度
				padding: 0 15px; // 内边距
				border: 2px solid $green-border-color; // 绿色边框
				border-radius: 25px 0 0 25px; // 左侧圆角
				background-color: $input-background-color; // 背景颜色
				color: $text-color; // 文字颜色
				font-size: $input-font-size; // 字体大小
				transition: all 0.3s ease; // 平滑过渡效果

				&:hover {
					border-color: $darker-green-border-color; // 更深的绿色
				}

				&:focus {
					border-color: $darkest-green-border-color; // 更深的绿色
					outline: none; // 移除默认轮廓
					box-shadow: 0 0 10px $shadow-color; // 添加阴影
				}
			}

			.search-button {
				width: 20%; // 调整宽度以适应屏幕大小
				height: 40px; // 按钮高度
				padding: 0 15px; // 内边距
				border: 2px solid $green-border-color; // 绿色边框
				border-radius: 0 25px 25px 0; // 右侧圆角
				background-color: $green-border-color; // 绿色背景
				color: $button-text-color; // 文字颜色
				font-size: $input-font-size; // 字体大小
				cursor: pointer; // 鼠标指针样式
				transition: all 0.3s ease; // 平滑过渡效果

				&:hover {
					background-color: $darker-green-border-color; // 更深的绿色
				}

				&:active {
					background-color: $darkest-green-border-color; // 更深的绿色
				}
			}
		}

		.sub-container {
			padding: 0 30rpx;
			margin-top: 30rpx;
		}

		.info-container {
			padding: 20rpx;
			flex: 1;

			.info-card {
				display: flex;
				align-items: flex-start;
				border: 1px solid #ddd;
				border-radius: 8px;
				padding: 16px;
				background-color: #fff;
				box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);

				.doctor-avatar {
					width: 80px;
					height: 80px;
					border-radius: 50%;
					margin-right: 16px;
				}

				.info-section {
					flex: 1;

					.card-header {
						display: flex;
						justify-content: flex-start;
						margin-bottom: 16px;

						.title {
							font-size: 18px;
							font-weight: bold;
							color: #333;
						}
					}

					.card-body {
						.item {
							display: flex;
							justify-content: space-between;
							align-items: center;
							margin-bottom: 8px;

							.label {
								font-size: 16px;
								color: #666;
							}

							.value {
								font-size: 16px;
								color: #333;
							}
						}
					}
				}
			}
		}
	}
</style>